package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.PhysiqueAssessment;
import com.itheima.pojo.Report;
import com.itheima.pojo.RiskAssessmentReport;
import com.itheima.pojo.RiskParams;
import com.itheima.service.PhysiqueAssessmentService;
import com.itheima.service.RiskAssessmentService;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ZS
 */
@RestController
@RequestMapping("riskAssessment")
public class RiskAssessmentController {

    @Reference(version = "1.0.0")
    private RiskAssessmentService riskAssessmentService;

    /**
     *  根据fileNumber查找体检报告
     * @param fileNumber 体检报告fileNumber
     * @return result
     */
    @GetMapping("findReportByFileNumber")
    public Result findReportByFileNumber( String fileNumber){
        return riskAssessmentService.findReportByFileNumber(fileNumber);
    }

    /**
     *   新增体检风险评估
     * @param params
     * @return
     */
    @PostMapping("addRiskAssessment")
    public Result addRiskAssessment(@RequestBody RiskParams params){
        String fileNumber = params.getFileNumber();
        List<Report> report = params.getReport();
        return   riskAssessmentService.addRiskAssessment(fileNumber, report);
    }


 /**
     * 根据fileNumber查询风险报告
     * @param fileNumber    风险报告中的档案号
     * @return  返回结果 list
     */
    @GetMapping("findRiskReportByFileNumber/{fileNumber}")
//    @PreAuthorize("hasAuthority('CHECKGROUP_QUERY')")
    public Result findById(@PathVariable String fileNumber){
        List<RiskAssessmentReport> riskAssessmentReport = riskAssessmentService.findById(fileNumber);
        return new Result(true,"查询成功",riskAssessmentReport);
    }

    /**
     * 删除
     * @param fileNumber 要删除的风评的fileNumber
     * @return  删除成功
     */
    @GetMapping("delete/{fileNumber}")
//    @PreAuthorize("hasAuthority('CHECKGROUP_DELETE')")
    public Result delete(@PathVariable String fileNumber){
        //调用业务层删除方法
        riskAssessmentService.delete(fileNumber);
        //返回操作结果
        return new Result(true, "删除风评成功");
    }

    /**
     * 分页查询方法
     * @param queryPageBean 分页参数实体类
     * @return  分页查询结果，总条数与当前页数据
     */
    @RequestMapping("findPage")
//    @PreAuthorize("hasAuthority('CHECKGROUP_QUERY')")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = riskAssessmentService.findPage(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }
}
